package test.src.awt_swing;

import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;

public class JTabbedPaneDemo {
    JFrame jFrame = new JFrame("这里测试JTabbedPane");

    JTabbedPane jTabbedPane = new JTabbedPane(SwingConstants.LEFT, JTabbedPane.SCROLL_TAB_LAYOUT);

    private void init() {
        // 组装视图
        jFrame.setPreferredSize(new Dimension(1080, 720));
//        jFrame.setResizable(false);

        ImageIcon icon = new ImageIcon("test\\src\\awt_swing\\img\\container\\open.gif");

        jTabbedPane.addTab("用户管理", icon, new JList<String>(new String[]{"用户一", "用户二", "用户三"}));
        jTabbedPane.addTab("商品管理", new JList<String>(new String[]{"商品一", "商品二", "商品三"}));
        jTabbedPane.addTab("订单管理", icon, new JList<String>(new String[]{"订单一", "订单二", "订单三"}));

        jTabbedPane.setEnabledAt(1, false);

        jTabbedPane.addChangeListener(new ChangeListener() {
            @Override
            public void stateChanged(ChangeEvent e) {
                int selectedIndex = jTabbedPane.getSelectedIndex();
                JOptionPane.showMessageDialog(jFrame, "您选中了第" + (selectedIndex) + "个标签");
            }
        });

        jFrame.add(jTabbedPane);

        jFrame.pack();
        jFrame.setVisible(true);

    }

    public static void main(String[] args) {
        new JTabbedPaneDemo().init();
    }
}
